package test3;

import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;

public class Consumer implements Callable<Boolean> {

    private Resource resource = Resource.getInstance();

    private CountDownLatch latch;

    private ProducerCustomerBlockingQueue queue = ProducerCustomerBlockingQueue.getInstance();

    public Consumer(CountDownLatch latch){
        this.latch = latch;
    }

    @Override
    public Boolean call(){
        while(latch.getCount() != 0){
            String rawDate = queue.take();
            resource.put(rawDate);
            latch.countDown();
        }
        return true;
    }

}
